<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../assets/font/iconfont.css">
    <link rel="stylesheet" href="./css/userCard.css">
    <link rel="stylesheet" href="../assets/notice/notice.css">
    <script src="../assets/notice/notice.js"></script>
    <script src="../assets/axios/axios.js"></script>
    <script src="./utils/request.js"></script>
    <script>
        /*
            forEach(function (u) {
                    temp += `
                        <div class="user-card">
                            <div class="head">
                                <img src="${u.img}p" alt="" srcset="">
                            </div>
                            <div class="info">
                                <div class="row">
                                    <span>编号</span>
                                    <span>${u.No}</span>
                                </div>
                                <div class="row">
                                    <span>姓名</span>
                                    <span>${u.name}</span>
                                </div>
                                <div class="row">
                                    <span>性别</span>
                                    <span>${u.sex}</span>
                                </div>
                                <div class="row">
                                    <span>手机号码</span>
                                    <span>${u.tel}</span>
                                </div>
                            </div>
                        </div>
                    `
                });
                let listBox = document.querySelector(".user-list");
                listBox.innerHTML = temp
        
        */
        function loadUserList() {
            axios.get("http://127.0.0.1:3000/api/list")
                .then(function (data) {
                    // 服务器通知业务结果错误
                    if(!data.state){
                        notice({
                            icon:"error",
                            title:data.msg
                        })
                        return;
                    }
                    notice({
                        icon:"success",
                        title:"数据加载成功"
                    })
                    let temp = "";
                    data.users.forEach(function (u) {
                        temp += `
                        <div class="user-card">
                            <div class="head">
                                <img src="${u.img}p" alt="" srcset="">
                            </div>
                            <div class="info">
                                <div class="row">
                                    <span>编号</span>
                                    <span>${u.No}</span>
                                </div>
                                <div class="row">
                                    <span>姓名</span>
                                    <span>${u.name}</span>
                                </div>
                                <div class="row">
                                    <span>性别</span>
                                    <span>${u.sex}</span>
                                </div>
                                <div class="row">
                                    <span>手机号码</span>
                                    <span>${u.tel}</span>
                                </div>
                            </div>
                        </div>
                    `
                    });
                    let listBox = document.querySelector(".user-list");
                    listBox.innerHTML = temp
                })
        }
    </script>
</head>

<body>
    <input type="button" value="ajax-业务逻辑错误" onclick="loadUserList()">
    <hr>
    <div class="user-list"></div>
</body>

</html>